#include <stdio.h>
#include <string.h>

struct Xxx {
	char aa[30];
	int bb[2];
	double cc;
};

struct Yyy {
	char dd[50];
	// 结构作为另一个结构的成员
	struct Xxx mm;
	// 指针变量作为结构的成员
	char *ee;
	// 指针数组作为结构的成员
	char *ff[3];
};

/**
 * 结构成员
 */
int main() {
	struct Xxx qq = {"Sample", {0, 1}, 5.4};
	struct Yyy nn = {"String constant",
					 {"Text", {7, 8}, 12.3},
					 "Address", {"a", "b", "c"}};
	struct Yyy pp, rr;

	strcpy(pp.dd, "Structure ");
	strcpy(pp.mm.aa, "in structure");
	pp.mm.bb[0] = 10;
	pp.mm.bb[0] = 12;
	pp.mm.cc = 57.82;
	pp.ee = "Pointer and ";
	pp.ff[0] = "array ";
	pp.ff[1] = "of ";
	pp.ff[2] = "pointers. ";

	// 将一个结构的所有成员的值拷贝到另一个结构变量的成员内存中
	rr = pp;

	printf("qq: [aa = %s, bb = [%d, %d], cc = %lf]\n",
		   qq.aa, qq.bb[0], qq.bb[1], qq.cc);

	printf("nn: [dd = %s, mm = [aa = %s, bb = [%d, %d], cc = %lf], "
		   "ee = %s, ff = [%s, %s, %s]]\n", nn.dd, nn.mm.aa, nn.mm.bb[0],
		   nn.mm.bb[1], nn.mm.cc, nn.ee, nn.ff[0], nn.ff[1], nn.ff[2]);

	printf("pp: [dd = %s, mm = [aa = %s, bb = [%d, %d], cc = %lf], "
		   "ee = %s, ff = [%s, %s, %s]]\n", pp.dd, pp.mm.aa, pp.mm.bb[0],
		   pp.mm.bb[1], pp.mm.cc, pp.ee, pp.ff[0], pp.ff[1], pp.ff[2]);

	printf("rr: [dd = %s, mm = [aa = %s, bb = [%d, %d], cc = %lf], "
		   "ee = %s, ff = [%s, %s, %s]]\n", rr.dd, rr.mm.aa, rr.mm.bb[0],
		   rr.mm.bb[1], rr.mm.cc, rr.ee, rr.ff[0], rr.ff[1], rr.ff[2]);
}

